<?php 

/**
 * 个人中心
 * @Author      jiating
 * @DateTime    2018-04-14
 */

namespace app\admin\controller;

use app\admin\model\Operator;
use think\Request;

class Center extends Base{

	public function __construct() {
		parent::__construct();
		$this->model = new Operator;
	}

	public function index() {
		return $this->fetch('operator:center');
	}

	public function editPost() {
		$data = input('post.');
		$id = session('member')['id'];
		$data['updateDate'] = date('Y-m-d H:i:s',time());
		$data['updateOper'] = $id;
		$upd = $this->model->where(['id'=>$id])->update($data);
		if($upd){
			return json(['code'=>'1','message'=>'修改成功']);
		} else {
			return json(['code'=>'2','message'=>'失败，请重试']);
		}
	}

	public function editPasswd() {
		$request = Request::instance();
        $param = $request->param();

        $id = session('member')['id'];
        $row = $this->model->where('id',$id)->find();
        if($row['password'] != md5($param['password'])) {
        	return json(['code'=>'2','message'=>'原密码错误，请重试']);
        }
        if($param['password1'] != $param['password2']) {
        	return json(['code'=>'2','message'=>'两次密码不一致，请重试']);
        }
        $data['updateDate'] = date('Y-m-d H:i:s',time());
		$data['updateOper'] = $id;
		$data['password'] = md5($param['password1']);
        $upd = $this->model->where(['id'=>$id])->update($data);
        if($upd){
			return json(['code'=>'1','message'=>'修改成功']);
		} else {
			return json(['code'=>'2','message'=>'失败，请重试']);
		}

	}


}